/*
 * Copyright 2008 Federal Emergency Management Agency
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0 
 *    
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 *  
 */
package gov.fema.hazus.bdc.client.hazards.earthquake;

import gov.fema.hazus.bdc.client.common.ui.AbstractWidget;
import gov.fema.hazus.bdc.client.common.ui.InCASTTabPanel;
import gov.fema.hazus.bdc.client.hazards.earthquake.bracing.BracingForm;
import gov.fema.hazus.bdc.client.hazards.earthquake.buildingdesign.EarthquakeBuildingDesignForm;
import gov.fema.hazus.bdc.client.hazards.earthquake.hazard.EarthquakeHazardForm;
import gov.fema.hazus.bdc.client.hazards.earthquake.secondarycharacteristics.EarthquakeSecondaryCharacteristicsForm;
import gov.fema.hazus.bdc.shared.entity.Building;

import com.google.gwt.user.client.ui.DockPanel;

public class EarthquakeWidget extends AbstractWidget {

	private DockPanel docker;
	private InCASTTabPanel tabPanel;
	
	// forms
	EarthquakeHazardForm earthquakeHazardForm;
	EarthquakeBuildingDesignForm earthquakeBuildingDesignForm;
	EarthquakeSecondaryCharacteristicsForm earthquakeSecondaryCharacteristicsForm;
	BracingForm bracingForm;
	
	public EarthquakeWidget(Building building)
	{
		
		docker = new DockPanel();
		
		// set up a tab panel
		tabPanel = new InCASTTabPanel();
		tabPanel.setWidth("100%");
		
		// setup forms
		earthquakeHazardForm = new EarthquakeHazardForm(building);
		earthquakeHazardForm.setStyleName("building-detail-form");
		earthquakeBuildingDesignForm = new EarthquakeBuildingDesignForm(building);
		earthquakeBuildingDesignForm.setStyleName("building-detail-form");
		earthquakeSecondaryCharacteristicsForm = new EarthquakeSecondaryCharacteristicsForm(building);
		earthquakeSecondaryCharacteristicsForm.setStyleName("building-detail-form");
		bracingForm = new BracingForm(building);
		bracingForm.setStyleName("building-detail-form");
		
		// add forms
		tabPanel.add(earthquakeHazardForm, earthquakeHazardForm.getTabTitle());
		tabPanel.add(earthquakeBuildingDesignForm, earthquakeBuildingDesignForm.getTabTitle());
		tabPanel.add(earthquakeSecondaryCharacteristicsForm, earthquakeSecondaryCharacteristicsForm.getTabTitle());
		tabPanel.add(bracingForm, "Bracing");
		
		// default
		tabPanel.selectTab(0);
		
		// add tabs to docker
		docker.add(tabPanel, DockPanel.CENTER);
		
		// add a style to the sub tabs
		tabPanel.setStyleName("emcode-subnav-tabbar");

		initWidget(docker);
		
	}


	public void updateBuilding(Building building) {
		
		earthquakeHazardForm.updateBuilding(building);
		earthquakeBuildingDesignForm.updateBuilding(building);
		earthquakeSecondaryCharacteristicsForm.updateBuilding(building);
		bracingForm.updateBuilding(building);
		
	}
}
